import cv2
import numpy as np

img1 =cv2.imread("9\\lena_gray.jpg")
img2 =cv2.imread("9\\3.bmp")

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))

tophat1 = cv2.morphologyEx(img1, cv2.MORPH_TOPHAT, kernel)
tophat2 = cv2.morphologyEx(img2, cv2.MORPH_TOPHAT, kernel)


cv2.imshow("img1",img1)
cv2.imshow("tophat1",tophat1)
cv2.imshow("img2",img2)
cv2.imshow("tophat2",tophat2)
cv2.waitKey()
cv2.destroyAllWindows()